package com.example.farmeri.tools;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

// 检验输入内容是否合法
public class TextFilterUtils {

    public static boolean filterIllegalText(String text,int min,int max) {
        return filterIllegalText(text, min, max,"");
    }

    public static boolean filterIllegalText(String text,int min,int max,String filter){
//        if (text.length() < min
//            || text.length() > max){
//            return false;
//        }
        if (TextUtils.isEmpty(filter)){
            filter="^[a-zA-Z0-9_\\u4e00-\\u9fa5]{"+min+","+max+"}$";
        }
        Pattern pattern = Pattern.compile(filter);
        Matcher matcher = pattern.matcher(text);
        return matcher.matches();
    }




}
